import request from "@/utils/request";

/**
 * 创建群聊
 * @param {object} data 群聊信息
 */
export function createGroupApi(data) {
  return request({
    url: "/group/create",
    method: "post",
    data: data,
  });
}

/**
 * 修改群聊信息
 * @param {object} data 群聊信息
 */
export function modifyGroupApi(data) {
  return request({
    url: "/group/modify",
    method: "put",
    data: data,
  });
}

/**
 * 解散群聊
 * @param {number} groupId 群聊ID
 */
export function deleteGroupApi(groupId) {
  return request({
    url: `/group/delete/${groupId}`,
    method: "delete",
  });
}

/**
 * 查询群聊信息
 * @param {number} groupId 群聊ID
 */
export function findGroupApi(groupId) {
  return request({
    url: `/group/find/${groupId}`,
    method: "get",
  });
}

/**
 * 获取群聊列表
 */
export function getGroupsApi() {
  return request({
    url: "/group/list",
    method: "get",
  });
}

/**
 * 邀请好友进群
 * @param {object} data
 * @param {number} data.groupId 群聊ID
 * @param {Array<number>} data.friendIds 好友ID列表
 */
export function inviteToGroupApi(data) {
  return request({
    url: "/group/invite",
    method: "post",
    data: data,
  });
}

/**
 * 查询群聊成员
 * @param {number} groupId 群聊ID
 */
export function getGroupMembersApi(groupId) {
  return request({
    url: `/group/members/${groupId}`,
    method: "get",
  });
}

/**
 * 将成员移出群聊
 * @param {object} data
 * @param {number} data.groupId 群聊ID
 * @param {number} data.userId 用户ID
 */
export function removeGroupMembersApi(data) {
  return request({
    url: "/group/members/remove",
    method: "delete",
    data: data,
  });
}

/**
 * 将用户踢出群聊 (后端已废弃)
 * @param {object} data
 * @param {number} data.groupId 群聊ID
 * @param {number} data.userId 用户ID
 */
export function kickGroupApi(data) {
  const { groupId, userId } = data;
  return request({
    url: `/group/kick/${groupId}`,
    method: "delete",
    params: { userId },
  });
}

/**
 * 退出群聊
 * @param {number} groupId 群聊ID
 */
export function quitGroupApi(groupId) {
  return request({
    url: `/group/quit/${groupId}`,
    method: "delete",
  });
}

/**
 * 设置群聊消息免打扰
 * @param {object} data
 * @param {number} data.groupId 群聊ID
 * @param {boolean} data.isDnd 是否免打扰
 */
export function setGroupDndApi(data) {
  return request({
    url: "/group/dnd",
    method: "put",
    data: data,
  });
}
